<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCronicasComentariosTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create( "cronicas_comentarios", function ($table) {
			$table->integer( 'cronica_id' )->unsigned();
			$table->foreign( 'cronica_id' )->references( 'id' )->on( 'cronicas' )->onDelete('cascade');
			$table->integer( 'comentario_id' )->unsigned()->unique();
			$table->foreign( 'comentario_id' )->references( 'id' )->on( 'comentarios' )->onDelete('cascade');
			$table->primary(array('comentario_id','cronica_id'));
		} );
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		
		Schema::table('cronicas_comentarios', function($table)
		{
			$table->dropForeign('cronicas_comentarios_cronica_id_foreign');
			$table->dropForeign('cronicas_comentarios_comentario_id_foreign');
		});
		
		Schema::dropIfExists( "cronicas_comentarios");
	}

}
